package com.blank.gpstest;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: blank
 * @date : 2022/7/22
 * @desc :
 * @url : https://gitee.com/hyx_blank
 */
public class MyReAdapter extends RecyclerView.Adapter<MyReAdapter.ViewHolder> {
    private List<String> strings;
    private LayoutInflater mInflater = null;
    private Context context;

    public MyReAdapter(Context context) {
        this.mInflater = LayoutInflater.from(context);
        strings = new ArrayList<>();
    }

    /**
     *
     */
    @NonNull
    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        //寻找项的布局文件
        View view = mInflater.inflate(R.layout.item_list, parent, false);
        return new ViewHolder(view);
    }

    /**
     * @param holder   The ViewHolder which should be updated to represent the contents of the
     *                 item at the given position in the data set.
     * @param position The position of the item within the adapter's data set.
     */
    @Override
    public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
        holder.title.setText(position + "***" + strings.get(position));
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    /**
     * Returns the total number of items in the data set held by the adapter.
     *
     * @return The total number of items in this adapter.
     */
    @Override
    public int getItemCount() {
        return strings.size();
    }

    public void setData(List<String> list) {
        strings = list;
        notifyDataSetChanged();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView title;

        public ViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            title = itemView.findViewById(R.id.id_treenode_name);
        }

    }
}
